angular.module('baisonGoods', ['baisonDb', 'baisonService'])
        //商品数据模型----------------------------------------------------------
        .factory('BaseGoods', ['$q', '$rootScope', 'dbSelect', 'dbUpdate', 'dbGetOne', 'dbReplace', 'apiService', 'dbTrans', 'dbGetOneSync', function ($q, $rootScope, dbSelect, dbUpdate, dbGetOne, dbReplace, apiService, dbTrans, dbGetOneSync) {
                //根据code获取商品sku信息  ======================================
                var get_sku_by_code = function (keywords) {
                    var deferred = $q.defer();
                    var promise = deferred.promise;
                    var key = new String(keywords);
                    //查询的字符串不为空
                    if ('' == keywords || key.length < 1) {
                        deferred.reject($rootScope.language.MSG_INPUT_MORE_THREE);
                        return promise;
                    } else {
                        var configData = $api.getStorage('configData');
                        var conditionStr = "";
                        //模糊匹配模式
                        switch(configData.searchMacthType){
                            case "match_tail": conditionStr = "%" + keywords;//尾部
                            break;
                            case "match_head": conditionStr = keywords + "%";//首部
                            break;
                            case "match_any": conditionStr = "%" + keywords + "%";//任意
                            break;
                            default:
                            conditionStr = "%" + keywords;
                            break;
                        }

                        //首先根据barcode精确查询
                        //var sql_barcode = "select s.* from PosSku s inner join PosGoods g on s.GoodsCode = g.GoodsCode where s.SkuCode = (select SkuCode from PosBarcode where BarCode = '" + keywords + "') and g.GoodsStatus = 1  ";

                        //注意 异步查询
                        //return dbSelect('YsPos', sql_barcode).then(function(ret){
                            //if(ret == undefined || ret.length < 1){
                                //没查到, 再根据sku或GoodsCode进行模糊查询
                                var sql = 'select s.* from PosSku s inner join PosGoods g on s.GoodsCode = g.GoodsCode where (s.SkuCode like "' 
                        + conditionStr + '" or s.GoodsCode like "'+ conditionStr +'") and g.GoodsStatus = 1;';
                                return dbSelect('YsPos', sql);
                            //}else{
                            //    return ret;
                           // }
                        //});
                    }
                };


                //获取所有商品的sku陈列数和名字=========================================
                var getChenlieAndName_By_all_skus = function (n, m) {
                    var sql = 'select SkuCode,SkuChenlie,GoodsName, GoodsName_zh_tw, GoodsName_en from PosSku limit ' + n + "," + m;
                    return dbSelect('YsPos', sql);
                };
                //设置商品的陈列数
                var set_SkuChenlie = function (sku) {
                    return dbUpdate('PosSku', {'SkuChenlie': sku.num}, {'SkuCode': sku.SkuCode}).then(function (success) {
                        return dbSelect('YsPos', 'select SkuChenlie from  PosSku where SkuCode="' + sku.SkuCode + '"');
                    });
                };
                //批量设置商品的陈列数
                var set_SkuChenlieAll = function (num, skus) {
                    var data = [];
                    $.each(skus, function (i, n) {
                        data.push({
                            'SkuCode': n.SkuCode,
                            'SkuChenlie': num
                        });
                    });
                    return dbReplace('PosSku', data, ['SkuCode'], ['SkuChenlie']);
                };
                //根据大分类和小分类获取商品
                var get_goods_list_by_cate = function (cate, sort) {
                    return dbSelect('YsPos', 'select s.* from PosSku s inner join PosGoods g on s.GoodsCode = g.GoodsCode where g.CategoryCode="' + cate + '" and g.SortCode="' + sort + '"');
//                  return dbSelect('YsPos', 'select * from PosGoods inner join PosSku on PosGoods.GoodsCode = PosSku.GoodsCode where PosGoods.CategoryCode="' + cate + '" and PosGoods.SortCode="' + sort + '" limit ' + limit);
                };
                //根据sku获取商品名称
                var get_GoodsName_by_sku = function (sku) {
                    return dbGetOne('select GoodsName from PosSku where SkuCode="' + sku + '"');
                };
                //added by lqx maowei on 20170116 根据sku获取商品名称 同步方法
                var get_GoodsName_by_sku_sync = function (sku) {
                    return dbGetOneSync('select GoodsName from PosSku where SkuCode="' + sku + '"');
                };
                //added by lqx maowei on 20170419 根据goods_code 查询大小类
                var get_category_and_sort_by_posgoods = function (code){
                    return dbGetOneSync('select GoodsCode,SortCode,CategoryCode,weight,unit_name from PosGoods where GoodsCode="' + code + '"');
                    //return dbGetOneSync('select GoodsCode,SortCode,CategoryCode,weight,unit_name from PosGoods where GoodsCode="' + n.goods_code + '" order by CategoryCode desc, SortCode desc')
                }

                //获取库存账面数
                var get_stock_num_by_goodCode = function(goodCode){
                    var shop_code = $rootScope.current_shop.ShopCode;
                    var data = {
                        store_code: shop_code,
                        goods_code: goodCode
                    };
                    return apiService("report/stm_stock_analyse_report/get_stock_list", data);
                };
                //根据sku获取账面数、陈列数
                var getSkuNum_by_sku = function (sku) {
                    return dbGetOne('select SkuNum,SkuChenlie from PosSku where SkuCode="' + sku + '"');
                };
                //获取所有的skus
                var getAllReturnsSkus = function (n, m, brand_code) {
                    if (brand_code != '' && brand_code != undefined) {
                        var sql = 'select s.* from PosSku s inner join PosGoods g on s.GoodsCode =g.GoodsCode where g.brand_code = "' + brand_code + '" limit ' + n + "," + m;
                    } else {
                        var sql = 'select * from PosSku limit ' + n + "," + m;
                    }
                    return dbSelect('YsPos', sql);
                };
                //获取所有sku(库存同步需要使用)
                var getAllSkus = function (n, m) {
                    var sql = 'select * from PosSku limit ' + n + "," + m;
                    return dbSelect('YsPos', sql);
                };
                
				//从服务器下载库存数到本地（林清轩）优化版
				var get_skunum_from_goods_inv = function(first,second){
					var param = {};
					param.store_code = $rootScope.current_shop.ShopCode;
                    param.first = first;
					param.second = second;
					return apiService('base/goods/get_goods_inv_by_len', param);
				};
				
				//同步本地库存
				var syn_local_sku_num  = function(data){
					var Skus = [];
					$.each(data, function (i, n) {
						Skus.push({
							'SkuNum': n.num,
							'SkuCode': n.sku
						});
					});
					return dbReplace('PosSku', Skus, ['SkuCode'], ['SkuCode', 'SkuNum']);
				};
				
                //从服务器下载库存数到本地（林清轩）
                var getSkuNum_by_api_skus = function (skus) {
                    var sku_array = [];
                    var Skus = [];
                    $.each(skus, function (i, n) {
                        sku_array.push({
                            'goods_code': n.GoodsCode,
                            'color_code': n.ColorCode,
                            'size_code': n.SizeCode,
                            'sku': n.SkuCode
                        });
                    });
                    var param = {};
                    param.store_code = $rootScope.current_shop.ShopCode;
                    param.skus = sku_array;
                    return apiService('base/goods/get_goods_inv_by_skus', param).then(function (ret) {
                        if (ret.data.status == 1) {
                            $.each(ret.data.data, function (i, n) {
                                Skus.push({
                                    'SkuNum': n.num,
                                    'SkuCode': n.sku
                                });
                            });
                            return dbReplace('PosSku', Skus, ['SkuCode'], ['SkuCode', 'SkuNum']);
                        } else {
                            return false;
                        }
                    });
                };
                //获取库存到本地（对接ipos）使用
                var getSkuNum_by_store_code = function (is_all) {
                    var Skus = [];
                    var pageNum = 1;
                    var bool = true;
                    while (bool) {
                        var param = {};
                        param.store_code = $rootScope.current_shop.ShopCode;
                        param.pageNum = pageNum;               
                        param.is_all = is_all;
                        return apiService('base/goods/get_goods_inv_by_shop_code', param).then(function (ret) {
                            if (ret.data.status == 1) {
                                if (ret.data.data.page == ret.data.data.page_count) {
                                    bool = false;
                                }
                                pageNum = ret.data.data.page + 1;
                                $.each(ret.data.data.data, function (i, n) {
                                    Skus.push({
                                        'SkuNum': n.num,
                                        'SkuCode': n.sku
                                    });
                                });
                                return dbReplace('PosSku', Skus, ['SkuCode'], ['SkuCode', 'SkuNum']);
                            } else {
                                return false;
                            }
                        });
                    }
                }

                //服务器获取在库库存和在途库存
                var getStockNumAndRoadNum_by_api_skus = function (goods) {
                    var sku_array = [];
                    sku_array.push({
                        'goods_code': goods.GoodsCode,
                        'color_code': goods.ColorCode,
                        'size_code': goods.SizeCode,
                        'sku': goods.SkuCode
                    });
                    var param = {};
                    param.store_code = $rootScope.current_shop.ShopCode;
                    param.skus = sku_array;
                    return apiService('base/goods/get_goods_inv_by_skus', param);
                };
                //根据商店 商品查询
                var getStockNumAndRoadNum_by_shopCode_skus = function (goods_code, shop_code) {
                    //api.alert({msg:goods,title:'1111'});
//                  var sku_array = [];
//                  sku_array.push({
//                      'goods_code': goods[0].GoodsCode,
//                      'color_code': goods[0].ColorCode,
//                      'size_code': goods[0].SizeCode,
//                      'sku': goods[0].SkuCode
//                  });
                    var param = {};
                    param.shop_code = shop_code;//shopCode
                    param.goods_code = goods_code;//'D2Q2D0081DR';//goodsCodes
                    return apiService('base/shop/get_friend_shop_goods', param);
                };

                //查询并显示三十天库存变化情况
                var stock_change_by_sku = function (goods) {
                    var param = {
                        'fields': 'stock_num,road_num',
                        'sku': goods.SkuCode,
                        'store_code': $rootScope.current_shop.ShopCode
                    };
                    return apiService('report/store/stock_stream_by_sku', param);
                };
                
                //获取库存信息
                var get_stock_list = function (goodCode) {
                    var shop_code = $rootScope.current_shop.ShopCode;
                    var data = {
                        store_code: shop_code,
                        goods_code: goodCode
                    };
                    return $q.all({
                        'data': apiService("report/stm_stock_analyse_report/get_stock_list", data),
                        'price':get_sku_by_code(goodCode)   //dbSelect('YsPos', 'select * from PosSku where SkuCode like "%' + goodCode + '"')
                    });
                };
                
                //获取本店库存大于1的商品
                var get_all_good_by_SkuNum = function (skunum_type, n, m) {
                    /*var sql = 'select * from PosSku where SkuNum != 0 and GoodsCode NOTNULL limit ' + n + "," + m;
                    if (skunum_type == 1) {
                        sql = 'select * from PosSku where  GoodsCode NOTNULL limit ' + n + "," + m;
                    }else if(skunum_type == 2){
                        sql = 'select * from PosSku where SkuNum != 0  and GoodsCode NOTNULL ORDER BY  SkuCode  ASC';
                    }
                    return dbSelect('YsPos', sql);*/
					var in_values = 'TZZK002298';
					var sql = 'select * from PosSku where SkuNum != 0 and GoodsCode NOTNULL and GoodsCode NOT IN ( "TZZK002298" ) limit ' + n + "," + m;
                    if (skunum_type == 1) {
                        sql = 'select * from PosSku where  GoodsCode NOTNULL and GoodsCode NOT IN ( "TZZK002298" ) limit ' + n + "," + m;
                    }else if(skunum_type == 2){
                        sql = 'select * from PosSku where SkuNum != 0  and GoodsCode NOTNULL and GoodsCode NOT IN ( "TZZK002298" ) ORDER BY  SkuCode  ASC';
                    }
					return dbSelect('YsPos', sql);
                };
                //退货原因
                var returnReason = function () {
                    var sql = 'select * from Pos_return_reason';
                    return dbSelect('YsPos', sql);
                };
                //获取商品的总记录数
                var get_all_len_skus = function () {
                    var sql = 'select count(*) num from PosSku';
                    return dbSelect('YsPos', sql);
                };
                //批量获取商品sku
                var get_batch_skus = function (offset, base_num) {
                    var sql = 'select SkuCode from PosSku limit ' + offset + ',' + base_num;
                    return dbSelect('YsPos', sql);
                };
                //批量获取商品sku价格
                var get_batch_skus_price = function (param) {
                    return apiService('base/goods/get_batch_goods_price', param);
                };
                //批量更新商品sku价格
                var update_batch_skus_price = function (sku) {
                    var _data = [];
                    $.each(sku, function (i, n) {
                        var _s = {};
                        _s.SkuCode = n.goods_code;
                        _s.SkuPrice = n.sell_price;
                        _s.SkuVipPrice = n.sell_price1;
                        _data[i] = _s;
                    });
                    return dbReplace('PosSku', _data, ['SkuCode'], ['SkuPrice', 'SkuVipPrice']);

                };
                //获取本地库存不等于0的sku
                var get_skus_by_num_exists = function(){
                    var num = 0;
                	var sql = 'select * from PosSku where SkuNum != "'+num+'"';
                	return dbSelect('YsPos', sql);
                };
				var get_goods_values = function(in_values){
					var sql = "SELECT g.weight,s.* from PosGoods g INNER JOIN PosSku s on g.GoodsCode = s.GoodsCode where g.GoodsCode in ( "+in_values+")";
					return dbSelect('YsPos',sql);
				};

				
                return {
                    get_all_good_by_SkuNum: get_all_good_by_SkuNum,
                    get_sku_by_code: get_sku_by_code,
                    getAllReturnsSkus: getAllReturnsSkus,
                    getChenlieAndName_By_all_skus: getChenlieAndName_By_all_skus,
                    set_SkuChenlie: set_SkuChenlie,
                    set_SkuChenlieAll: set_SkuChenlieAll,
                    get_goods_list_by_cate: get_goods_list_by_cate,
                    get_GoodsName_by_sku: get_GoodsName_by_sku,
                    get_GoodsName_by_sku_sync: get_GoodsName_by_sku_sync,
                    get_category_and_sort_by_posgoods: get_category_and_sort_by_posgoods,
                    getSkuNum_by_sku: getSkuNum_by_sku,
                    get_stock_num_by_goodCode:get_stock_num_by_goodCode,
                    getAllSkus: getAllSkus,
                    getSkuNum_by_api_skus: getSkuNum_by_api_skus,
                    returnReason: returnReason,
                    getStockNumAndRoadNum_by_api_skus: getStockNumAndRoadNum_by_api_skus,
                    getStockNumAndRoadNum_by_shopCode_skus: getStockNumAndRoadNum_by_shopCode_skus,
                    stock_change_by_sku: stock_change_by_sku,
                    get_stock_list: get_stock_list,
                    get_all_len_skus: get_all_len_skus,
                    get_batch_skus: get_batch_skus,
                    get_batch_skus_price: get_batch_skus_price,
                    update_batch_skus_price: update_batch_skus_price,
                    getSkuNum_by_store_code: getSkuNum_by_store_code,
                    get_skus_by_num_exists:get_skus_by_num_exists,
					get_skunum_from_goods_inv:get_skunum_from_goods_inv,
					syn_local_sku_num:syn_local_sku_num,
					get_goods_values:get_goods_values
                };
            }])

        //优惠券模型------------------------------------------------------------
        .factory('Coupon', ['$q', 'dbSelect', 'apiService', function ($q, dbSelect, apiService) {
                //查找优惠券信息
                var coupon_search = function (filter) {
                    return apiService('crm/coupon/get_coupon', filter);
                };
                //核销优惠券（暂时不用）
                var check_coupon = function (filter) {
                    return apiService('crm/coupon/use_coupon', filter);
                };
                return {
                    coupon_search: coupon_search,
                    check_coupon: check_coupon
                };
            }])

        //储值卡模型
        .factory('Cards', ['$q', 'dbSelect', 'apiService', '$rootScope', function ($q, dbSelect, apiService, $rootScope) {
                //获取储值卡信息
                var cardsNo_search = function (code, password) {
                    return apiService('crm/vip/get_czk_info', {'czkCode': code, 'password': password});
                };
                //获取储值卡一人多卡信息
                var getCards_by_code = function (tel) {
                    var param = {};
                    param.tel = tel;
                    param.shop_code = $rootScope.current_shop.ShopCode;
                    return apiService('crm/vip/get_czk_info', param);
                };
                //储值卡挂失
                var prepaidCard = function (data) {
                    var param = {};
                    param.tel = data.tel;
                    param.shop_code = $rootScope.current_shop.ShopCode;
                    param.czkCode = data.czkCode;
                    return apiService('crm/vip/czkLoss', param);
                };
                //根据外卡卡号获取折扣
                var get_rebate_by_wildCard = function (data) {
                    var param = {};
                    param.cardNo = data;        //'xhx_1A1150_000001';                  //data;
                    param.shop_code = $rootScope.current_shop.ShopCode;       //'1A1150';              //$rootScope.current_shop.ShopCode;
                    return apiService('pos/pos/get_wildCard', param);
                };
                return {
                    cardsNo_search: cardsNo_search,
                    getCards_by_code: getCards_by_code,
                    prepaidCard: prepaidCard,
                    get_rebate_by_wildCard: get_rebate_by_wildCard
                };
            }])
        //缺货登记
        .factory('LackRegister', ['$q', 'dbSelect', 'apiService', '$rootScope', function ($q, dbSelect, apiService, $rootScope) {
                //生成商品订金单
                var addDepositRecord = function (data) {
                    
                    var param = {};
                    param = data;
                    param.shop_code = $rootScope.current_shop.ShopCode;
                    return apiService('pos/pos/add_depositRecord', param);
                };
                return {
                    addDepositRecord: addDepositRecord
                };
            }])
        //购物车模型------------------------------------------------------------
        .factory('GoodsCart', ['$rootScope', '$q', 'timeStamp2String', 'dbSelect', 'BaseGoods', 'PosUser', 'Promotion', 'SkuPrice',function ($rootScope, $q, timeStamp2String, dbSelect, BaseGoods, PosUser, Promotion,SkuPrice) {
                //获取vip_rebate 会员折扣
                var get_vip_rebate = function(){
                    if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                        if($rootScope.goods_cart.vip.enable_vip_price == 1){//使用会员价
                            return $rootScope.goods_cart.vip.rebate;
                        }else{
                            return 1;
                        }
                    } else {
                        return 1;
                    }
                };
                //检查是否是会员
                var check_vip = function(){
                    if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                        return false;
                    } else {
                        return true;
                    }
                };
                //计算商品价格 返回原价与会员价 对象｛'SkuPrice','SkuVipPrice'｝;
                var calculate_sku_price = function(sku){
                   var shop_code = $rootScope.current_shop.ShopCode;
                   var deferred = $q.defer();
                   var promise = deferred.promise;
                   var is_vip = false; //是否是会员
                   var is_adjust = false; //是否需调价
                   var adjust_type = -1; //调价类型
                   var adjust_price = 0;//调价价格 (收银价格)
                   var sku_price = 0;//调价的商品原价
                   var sku_vip_price = 0;//调价的商品vip价格
                   var adjust_rebate = 1;//调价折扣
                   var vip_rebate = 1;//会员折扣
                   var shop_price_index = -1;//店铺售价索引
                   var shop_price_rebate = 1; //店铺售价折扣
                   //会员信息
                   vip_rebate = get_vip_rebate();
                   is_vip = check_vip();
                   SkuPrice.check_adjust(shop_code,sku.SkuCode).then(function(main){
                       if(main.length > 0){//有调价单
                           SkuPrice.check_adjust_detail(sku.SkuCode,main[0].AdjustId).then(function(detail){
                               if(detail.length > 0){ //该商品有调价
                                   //设置商品价格相应字段值
                                   adjust_type = main[0].Adjust_Type;
                                   if(is_vip){ //是会员  //调价价格为售价4
                                       adjust_price = detail[0].Price;
                                       switch (adjust_type){
                                            case 0:{ //调价
                                                sku_price = adjust_price;
                                                adjust_price = adjust_price*vip_rebate; //调价单（售价4）×会员折扣
                                                sku_vip_price = adjust_price;
                                                break;
                                            }
                                            case 1:{ //调折
                                                break;
                                            }
                                            case 2:{ //调价调折
                                                adjust_price = adjust_price*detail[0].Rebate;
                                                sku_price = adjust_price;
                                                adjust_price = adjust_price*vip_rebate; //调价单（售价4）×调价单（售价4折扣）×会员折扣
                                                sku_vip_price = adjust_price;
                                                break;
                                            }
                                        }
                                        deferred.resolve({'SkuPrice':sku_price,'SkuVipPrice':sku_vip_price});
                                        
                                   }else{ //不是会员
                                       SkuPrice.get_shop_price_index(shop_code).then(function(ret){
                                           if(ret.length > 0){ //有店铺售价
                                               shop_price_index = ret[0].ShopPriceIndex-4;
                                               shop_price_index = (shop_price_index== 0)?'':shop_price_index;
                                               var pricename = 'Price'+shop_price_index;
                                               adjust_price = detail[0][pricename];
                                               switch (adjust_type){
                                                    case 0:{ //调价
                                                        adjust_price = adjust_price; //调价单（价格设定定售X）
                                                        break;
                                                    }
                                                    case 1:{ //调折
                                                        break;
                                                    }
                                                    case 2:{ //调价调折
                                                        adjust_price = adjust_price*detail[0].Rebate; //调价单（价格设定定售X）×调价单（折扣）
                                                        break;
                                                    }
                                                }
                                                sku_vip_price = adjust_price;
                                                sku_price = adjust_price;
                                           }
                                           deferred.resolve({'SkuPrice':sku_price,'SkuVipPrice':sku_vip_price});
                                       });
                                   }
                                   
                               }else{ //该商品不调价
                                   //获取定价商品表信息
                                   SkuPrice.get_pricing_info(sku.SkuCode).then(function(main){
                                       if(main.length > 0){ //该商品有定价
                                           if(is_vip){ //是会员 商品定价单（售价4）×客户表（店铺折扣）×会员折扣
                                                SkuPrice.get_shop_price_index(shop_code).then(function(ret){
                                                    if(ret.length > 0){ //有店铺售价
                                                        shop_price_rebate = ret[0].ShopRebate; //客户表（店铺折扣）
                                                        adjust_price = main[0].Price; //(售价4)
                                                        adjust_price = adjust_price*shop_price_rebate;
                                                        sku_price = adjust_price;
                                                        adjust_price = adjust_price*vip_rebate;//会员折扣
                                                        sku_vip_price = adjust_price;
                                                    }
                                                    deferred.resolve({'SkuPrice':sku_price,'SkuVipPrice':sku_vip_price});
                                                });
                                            }else{ //不是会员  商品定价单（价格设定售价X）×客户表（店铺折扣）
                                                SkuPrice.get_shop_price_index(shop_code).then(function(ret){
                                                    if(ret.length > 0){ //有店铺售价
                                                        shop_price_index = ret[0].ShopPriceIndex-4;
                                                        shop_price_index = (shop_price_index== 0)?'':shop_price_index;
                                                        shop_price_rebate = ret[0].ShopRebate; //客户表（店铺折扣）
                                                       
                                                        var pricename = 'Price'+shop_price_index;
                                                        adjust_price = main[0][pricename]; //价格设定售价X
                                                        adjust_price = adjust_price*shop_price_rebate;
                                                    }
                                                    sku_vip_price = adjust_price;
                                                    sku_price = adjust_price;
                                                    deferred.resolve({'SkuPrice':sku_price,'SkuVipPrice':sku_vip_price});
                                                });
                                            }
                                       }else{ //该商品没有定价 默认价格为0  因林清轩的版本 故 等于 sku.SkuPrice sku.SkuVipPrice
                                            //baison_app.api.alert({msg:'SkuCode:'+sku.SkuCode+$rootScope.language.TIPS_GOODS_NO_PRICE}); 
                                            sku_vip_price = sku.SkuVipPrice;//adjust_price;
                                            sku_price = sku.SkuPrice;//adjust_price;
                                            deferred.resolve({'SkuPrice':sku_price,'SkuVipPrice':sku_vip_price});
                                       }
                                   });
                               }
                           });
                       }else{ //没有调价单 
                           //获取定价商品表信息
                            SkuPrice.get_pricing_info(sku.SkuCode).then(function(main){
                                if(main.length > 0){ //该商品有定价
                                    if(is_vip){ //是会员 商品定价单（售价4）×客户表（店铺折扣）×会员折扣
                                        SkuPrice.get_shop_price_index(shop_code).then(function(ret){
                                            if(ret.length > 0){ //有店铺售价
                                                shop_price_rebate = ret[0].ShopRebate; //客户表（店铺折扣）
                                                adjust_price = main[0].Price; //(售价4)
                                                adjust_price = adjust_price*shop_price_rebate;
                                                sku_price = adjust_price;
                                                adjust_price = adjust_price*vip_rebate;//会员折扣
                                                sku_vip_price = adjust_price;
                                            }
                                            deferred.resolve({'SkuPrice':sku_price,'SkuVipPrice':sku_vip_price});
                                        });
                                    }else{ //不是会员  商品定价单（价格设定售价X）×客户表（店铺折扣）
                                        SkuPrice.get_shop_price_index(shop_code).then(function(ret){
                                            if(ret.length > 0){ //有店铺售价
                                                shop_price_index = ret[0].ShopPriceIndex-4;
                                                shop_price_index = (shop_price_index== 0)?'':shop_price_index;
                                                shop_price_rebate = ret[0].ShopRebate; //客户表（店铺折扣）
                                                
                                                var pricename = 'Price'+shop_price_index;
                                                adjust_price = main[0][pricename]; //价格设定售价X
                                                adjust_price = adjust_price*shop_price_rebate;
                                            }
                                            sku_vip_price = adjust_price;
                                            sku_price = adjust_price;
                                            deferred.resolve({'SkuPrice':sku_price,'SkuVipPrice':sku_vip_price});
                                        });
                                    }
                                }else{ //该商品没有定价 默认价格为0  因林清轩的版本 故 等于 sku.SkuPrice sku.SkuVipPrice
                                    //baison_app.api.alert({msg:'SkuCode:'+sku.SkuCode+$rootScope.language.TIPS_GOODS_NO_PRICE}); 
                                    sku_vip_price = sku.SkuVipPrice;//adjust_price;
                                    sku_price = sku.SkuPrice;//adjust_price;
                                    deferred.resolve({'SkuPrice':sku_price,'SkuVipPrice':sku_vip_price});
                                }
                            });
                       }
                   });
                   return promise;
                };
                //获取折扣
                var get_price_rebate = function (buyPrice, vipPrice) {
                    if (vipPrice == 0) {
                        return 1;
                    } else {
                        return buyPrice / vipPrice;
                    }
                };


                //商品部分 ====================================================
                //添加赠品处理逻辑
                var add_gift_to_cart_logic = function(sku, pid, ptype, price, goods_status){
                    if (!sku.index) {
                        sku.index = String(new Date().getTime()) + sku.SkuCode;
                    }

                    //购物车商品数量
                    if (!sku.num) {
                        sku.num = 1;
                    }
                    sku.goods_num = sku.num;
                    //调价单据计算价格
                   // return calculate_sku_price(sku).then(function(ret){
                    //购买价是使用原价还是会员价
                    if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                        sku.BuyPrice = sku.SkuPrice;
                    } else {
                        sku.BuyPrice = sku.SkuVipPrice;
                    }

                    //购买折扣
                    if (!sku.rebate) {
                        sku.rebate = get_price_rebate(sku.BuyPrice, sku.SkuPrice);
                    }
                    //导购字段
                    //TODO 根据当前收银员编号插入
                    if (typeof $rootScope.goods_cart.list == 'undefined' || $rootScope.goods_cart.list.length == 0) {
                        sku.daogou = (typeof $rootScope.user == 'undefined') ? '' : $rootScope.user.UserCode;
                    } else {
                        sku.daogou = $rootScope.goods_cart.list[0].daogou;
                    }


                    //购买金额
                    sku.money = parseFloat(price * sku.num);
                    sku.promotionid = pid;
                    sku.promotype = pid.toString() + ptype; //促销对应的赠品信息
                    sku.is_promotion = 1;
                    sku.price = price;
                    sku.pro_gift = 1; //是赠品
                    if(ptype != 5){

                    }
                    sku.goods_status = goods_status;//促销
                    sku.bind_pro = $rootScope.goods_cart.current_promotions[pid].record_code;
                    //$rootScope.goods_cart.current_promotions[pid].favorable_money = ($rootScope.goods_cart.current_promotions[pid].favorable_money?$rootScope.goods_cart.current_promotions[pid].favorable_money:0) + parseFloat(sku.BuyPrice - price) * sku.num*1;
                    //$rootScope.goods_cart.current_promotions[pid].dis_pro_money = ($rootScope.goods_cart.current_promotions[pid].dis_pro_money?$rootScope.goods_cart.current_promotions[pid].dis_pro_money: 0) + parseFloat(sku.BuyPrice - price) * sku.num*1;

                    $rootScope.goods_cart.list.push(sku);
                    //刷新购物车
                    $rootScope.goods_cart.info.cut_money = 0;
                };
                //添加赠品
                var add_gift_to_cart = function (sku, pid, ptype, price, goods_status) {
                    add_gift_to_cart_logic(sku, pid, ptype, price, goods_status);
                    return refresh_cart_num();
                };
                //向购物车添加一个商品
                var add_to_cart = function (sku, test, guide,flag) {
                    if(flag == 'jf'){
                        sku.is_jf = 1;
                    }
                    //baison_app.api.alert({msg:sku});
                    //TODO 索引默认用当前毫秒时间戳
                    if (sku.hasOwnProperty('index') == false || !sku.index) {
                        sku.index = String(new Date().getTime());
                    }
                    //baison_app.api.alert({msg:'here'});
                    //购物车商品数量
                    if (sku.hasOwnProperty('num') == false || !sku.num) {
                        sku.num = 1;
                    }
                    sku.goods_num = sku.num;
                    //调价单据计算价格
                    //calculate_sku_price(sku).then(function(ret){
                        //sku.SkuPrice = ret.SkuPrice;
                        //sku.SkuVipPrice = ret.SkuVipPrice;
                             //购买价是使用原价还是会员价
                    if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                        sku.BuyPrice = sku.SkuPrice;
                    } else {
                        sku.BuyPrice = sku.SkuVipPrice;
                    }
                    //购买折扣
                    if (!sku.rebate) {

                        if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                            sku.rebate = get_price_rebate(sku.BuyPrice, sku.SkuPrice);
                        } else {
                            sku.rebate = $rootScope.goods_cart.vip.rebate * get_price_rebate(sku.SkuVipPrice, sku.SkuPrice);
                        }

                    }
                    //导购字段
                    if (test == 0) {
                        if (typeof $rootScope.goods_cart.list == 'undefined' || $rootScope.goods_cart.list.length == 0) {
                            //默认导购
                            sku.daogou = guide;
                        } else {
                            sku.daogou = $rootScope.goods_cart.list[0].daogou;
                        }
                    } else if (typeof test == 'undefined') {
                    
                    } else {
                        sku.daogou = guide;
                    }

                    //购买金额
                    sku.money = parseFloat(sku.BuyPrice * sku.num);
                    sku.bind_pro = '';
                    sku.whole_pro = '';
                    $rootScope.goods_cart.list.push(sku);
                    //刷新购物车
                    $rootScope.goods_cart.info.cut_money = 0;
                    return refresh_cart_num();
                        
                    //}); //TODO 数据没有暂时写在这里
                };

                //批量向购物车添加商品
                var add_to_cart_batch = function (data) {
                    data.forEach(function (e) {
                        add_to_cart(e);
                    });
                };
                //增加促销物品购物车信息更新
                var refresh_group_promo_goods = function (info) {
                    var total_num = 0;
                    var total_money = 0;
                    var discount_money = 0;
                    var money = 0;
                    var lastprice = 0;
                    $.each($rootScope.goods_cart.list, function (i, v) {
                        var price = 0;
                        if(v.price >=0  && !v.is_jf && v.pro_gift && v.pro_gift ==1){ //促销赠品
                            lastprice = v.price;
                            if ($rootScope.goods_cart.current_promotions[v.promotionid]) {
                                if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                                    price = v.SkuPrice;
                                } else {
                                    price = v.SkuVipPrice;
                                }
                                discount_money = discount_money + parseFloat(price - lastprice) * v.num;
                                $rootScope.goods_cart.list[i].money = lastprice  * v.num;
                                $rootScope.goods_cart.list[i].BuyPrice = lastprice;
                                $rootScope.goods_cart.list[i].is_promotion = 1;
                            }
                            money = lastprice * v.num;
                            total_num = total_num * 1 + v.num * 1;
                            total_money = total_money + money;
                        }
                    });
                    info.total_num += total_num;
                    info.total_money += total_money;
                    return info;
                };
               
                //添加促销物品到购物车
                var add_gift_to_cartlist = function (gift_list, pid, ptype, goods_status) {
                    if (gift_list == undefined || gift_list == null) {
                        return;
                    }
                    
                    var i = 0;
                    var v = {};
                     //回调添加赠品函数
                    var callbark_add_gift = function(i){
                        v = gift_list[i];
                        if(v == undefined){
                            refresh_cart_num();
                            return;
                        }
                        BaseGoods.get_sku_by_code(v.sku).then(function (sku) {
                            if (sku[0] != undefined) {
                                if(ptype == 5){
                                    sku[0].num = v.num;
                                }else{
                                    sku[0].num = v.xz_num;
                                }

                                add_gift_to_cart_logic(sku[0], pid, ptype, v.price, goods_status);
								if(ptype == 5){ //套组
									$rootScope.goods_cart.g_giftednum++;
								}else{
									$rootScope.goods_cart.giftednum++;
								}
                                
                                i++;
                                callbark_add_gift(i);
                                
                                
                            }else{
                                baison_app.api.toast({msg:"没有商品代码为:"+v.sku+"商品"});
                                if(ptype == 5){ //套组
									$rootScope.goods_cart.g_giftednum++;
								}else{
									$rootScope.goods_cart.giftednum++;
								}
                                i++;
                                callbark_add_gift(i);
                            }
                        });
                    }
                    callbark_add_gift(i);
                };
                //刷新购物车信息
                var refresh_cart_info = function (index) {
                    //购买价是使用原价还是会员价
                    if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                        $rootScope.goods_cart.list[index].BuyPrice = $rootScope.goods_cart.list[index].SkuPrice;
                    } else {
                        $rootScope.goods_cart.list[index].BuyPrice = $rootScope.goods_cart.list[index].SkuVipPrice;
                    }
                    $rootScope.goods_cart.list[index].money = $rootScope.goods_cart.list[index].BuyPrice * $rootScope.goods_cart.list[index].num;
                    $rootScope.goods_cart.list[index].rebate = get_price_rebate($rootScope.goods_cart.list[index].BuyPrice, $rootScope.goods_cart.list[index].SkuPrice);
                    refresh_cart_num();
                };
                //设置购物车促销Id
                var set_cart_goods_promotion_id = function(){
                    $.each($rootScope.goods_cart.current_promotions, function (i, n) {
						n.goods_num = n.customer_num * n.can_used_num * 1;
                        if(n.isUse){
                            if(n.promotion_type == 0 ||n.promotion_type == 1 || n.promotion_type == 4 || n.promotion_type == 7){
                                $rootScope.goods_cart.list.forEach(function (o,j) {
                                    var wps = $rootScope.goods_cart.list[j].whole_pro?$rootScope.goods_cart.list[j].whole_pro:'';
                                    if(wps.indexOf(n.record_code) == -1){
                                        $rootScope.goods_cart.list[j].whole_pro = wps!= ''?wps+','+n.record_code:wps+n.record_code;
                                    }
                                    $rootScope.goods_cart.list[j].goods_status = 1;
									$rootScope.goods_cart.list[j].promotionid = n.promotion_rule_id; 
                                });
                            }
                            if(n.promotion_type == 2 || n.promotion_type == 3 || n.promotion_type == 8 || n.promotion_type == 9){  //customer_num can_used_num
                                $rootScope.goods_cart.list.forEach(function (o,j) {
                                   var index = n.goods_list.indexOf(o.SkuCode); //指定商品
                                   if(index != -1 && $rootScope.goods_cart.list[j].bind_pro == undefined){
									   if(n.goods_num > 0){
										   var del_num = $rootScope.goods_cart.list[j].num > n.goods_num?n.goods_num:$rootScope.goods_cart.list[j].num;
										   n.goods_num = n.goods_num - del_num;
										   $rootScope.goods_cart.list[j].goods_num = $rootScope.goods_cart.list[j].num - del_num;
										   var bps = $rootScope.goods_cart.list[j].bind_pro ?$rootScope.goods_cart.list[j].bind_pro:'';
										   if(bps.indexOf(n.record_code) == -1){
                                               $rootScope.goods_cart.list[j].bind_pro =bps != ''?bps+','+n.record_code:bps+n.record_code;
                                           }
										   $rootScope.goods_cart.list[j].goods_status = 1;
									   }else{
										   $rootScope.goods_cart.list[j].goods_num = $rootScope.goods_cart.list[j].num;
									   }
                                       
                                   }else if(n.goods_list.length <=0){//不指定商品
                                       if(n.goods_num > 0){
										   var del_num = $rootScope.goods_cart.list[j].num > n.goods_num?n.goods_num:$rootScope.goods_cart.list[j].num;
										   n.goods_num = n.goods_num - del_num;
										   $rootScope.goods_cart.list[j].goods_num = $rootScope.goods_cart.list[j].num - del_num;
                                           var bps = $rootScope.goods_cart.list[j].bind_pro ?$rootScope.goods_cart.list[j].bind_pro:'';
                                           if(bps.indexOf(n.record_code) == -1){
                                               $rootScope.goods_cart.list[j].bind_pro =bps != ''?bps+','+n.record_code:bps+n.record_code;
                                           }
										   $rootScope.goods_cart.list[j].goods_status = 1;
									   }else{
										   $rootScope.goods_cart.list[j].goods_num = $rootScope.goods_cart.list[j].num;
									   }
                                   }
                                });
                            }
                        }
                    });
                };
                //清空购物车促销Id (对应促销失效时)  取消促销时调用 
                var clear_cart_goods_promotion_id = function(promotionId){
                    var n = $rootScope.goods_cart.current_promotions[promotionId];
                    if(n.isUse){
                        if(n.promotion_type == 0 || n.promotion_type == 1 || n.promotion_type == 4 || n.promotion_type == 7){
                            $rootScope.goods_cart.list.forEach(function (o,j) {
                                var whole_pro_arr = $rootScope.goods_cart.list[j].whole_pro.split(',');
                                var wholelen = whole_pro_arr.length;
                                for(var i =0;i<wholelen;i++){
                                    var wholepro = whole_pro_arr[i];
                                    if(wholepro == n.record_code){
                                        whole_pro_arr.splice(i,1);
                                        break;
                                    }
                                }
                                console.log(whole_pro_arr);
                                if(whole_pro_arr.length <= 0){
                                    delete $rootScope.goods_cart.list[j].whole_pro;
                                    delete $rootScope.goods_cart.list[j].goods_status;
                                }else{
                                    var wholeprostr = whole_pro_arr.join(',');
                                    $rootScope.goods_cart.list[j].whole_pro = wholeprostr;
                                }
                            });
                        }else if(n.promotion_type == 2 || n.promotion_type == 3 || n.promotion_type == 8 || n.promotion_type == 9 || n.promotion_type == 10){
                            $rootScope.goods_cart.list.forEach(function (o,j) {
                                var bind_pro_arr = $rootScope.goods_cart.list[j].bind_pro.split(',');
                                var bindlen = bind_pro_arr.length;
                                for(var i =0;i<bindlen;i++){
                                    var bindpro = bind_pro_arr[i];
                                    if(bindpro == n.record_code){
                                        bind_pro_arr.splice(i,1);
                                        break;
                                    }
                                }
                                console.log(bind_pro_arr);
                                if(bind_pro_arr.length <= 0){
                                    delete $rootScope.goods_cart.list[j].bind_pro;
                                    delete $rootScope.goods_cart.list[j].goods_status;
                                }else{
                                    var bindprostr = bind_pro_arr.join(',');
                                    $rootScope.goods_cart.list[j].bind_pro = bindprostr;
                                }
                                
                            });
                        }
                    }
                };
                //改变绑定促销优惠券的使用标志
                var change_coupon_pro_flag = function(pid,num){
                    if($rootScope.goods_cart.couponData[pid] != undefined){
                        $rootScope.goods_cart.couponData[pid].coupon.coupon_code.forEach(function(n,i){
                            if(i < num){ 
                                $rootScope.goods_cart.couponData[pid].coupon.coupon_code[i].is_use = true;
                            }else{
                                $rootScope.goods_cart.couponData[pid].coupon.coupon_code[i].is_use = false;
                            }
                        });             
                    }
                };
				
				//判断会员是否可以使用该促销 true 可以 false 不可以
				var check_vip_can_use_pro = function(n){
					//不是会员
					if(!$rootScope.goods_cart.vip || $rootScope.goods_cart.vip.vip_code == ''){
						return true;
					}
					var hasvip = false;
					//是会员
					var vips = {};
					//会员等级
					var viplevels = {};
					//会员使用的促销信息
					var vipors = {};
					if(n.vip.length > 0){//该促销指定会员
						for(var i = 0; i < n.vip.length ;i ++){
							vips = n.vip[i];
							if(vips.vip_code == $rootScope.goods_cart.vip.vip_code){ //在指定vip范围内
								hasvip = true;
								break;
							}
						}
						if(hasvip){
							//判断使用次数是否可以使用
							for(var i = 0; i < $rootScope.goods_cart.vip.promotions.length; i++){
								vipors = $rootScope.goods_cart.vip.promotions[i];
								if(vipors.promo_code == n.record_code && vips.cnt <= vipors.cnt){
									return false;
								}
							}
						    return true;
								
								
								
								
						}
						return false;
					}
					if(n.viplevel.length > 0){ //该促销指定会员等级
						for(var i = 0; i < n.viplevel.length ;i ++){
							viplevels = n.viplevel[i];
							if(viplevels.level_code == $rootScope.goods_cart.vip.customer_level){ //在指定会员等级范围内
								hasvip = true;
								break;
							}
						}
						if(hasvip){
							//判断使用次数是否可以使用
							for(var i = 0; i < $rootScope.goods_cart.vip.promotions.length; i++){
								vipors = $rootScope.goods_cart.vip.promotions[i];
								if(vipors.promo_code == n.record_code && viplevels.cnt <= vipors.cnt){
									return false;
								}
							}
						    return true;
								
								
								
								
						}
						return false;
					}
					return true;
				};
				
				//无门槛促销处理逻辑
				var no_door_pro_logic = function(n){
					var dis_count_money = 0;
					var index = 0;
					$rootScope.goods_cart.list.forEach(function(e){
						if(n.goods_list && (index = n.goods_list.indexOf(e.SkuCode)) != -1){
							dis_count_money = dis_count_money + e.BuyPrice-n.goodslist[index].price;
							e.BuyPrice = n.goodslist[index].price;
							e.rebate = e.BuyPrice /($rootScope.goods_cart.vip && $rootScope.goods_cart.vip.vip_code) ? e.SkuVipPrice:e.SkuPrice;
							e.money = e.BuyPrice*e.num;
						}
					});
					return dis_count_money;
				};
                //获取促销优惠金额discount_money
                var get_promotion_discount_money = function (total_money) {
                    var discount_money = 0;
                    $.each($rootScope.goods_cart.available_promotions, function (i, n) {
                        if (Promotion.check_current_prom(n.promotion_rule_id, $rootScope.goods_cart.current_promotions)) {
                            switch (parseInt(n.promotion_type)){
                                case 0://满额立减
                                case 2://满件减钱
								case 7:
                                    discount_money = discount_money + parseFloat(n.reduce_price*n.can_used_num);
                                    $rootScope.goods_cart.current_promotions[n.promotion_rule_id].used_num = n.can_used_num;
                                    change_coupon_pro_flag(n.promotion_rule_id,n.can_used_num);
                                    $rootScope.goods_cart.current_promotions[i].dis_pro_money = parseFloat(n.reduce_price*n.can_used_num).toFixed(2);
                                    break;
                                case 4://满额打折 （打折促销不需要叠加使用）   
                                    discount_money = discount_money + ($rootScope.goods_cart.info.total_money - $rootScope.goods_cart.info.total_money * (0.1) * parseFloat(n.rebate));
                                    $rootScope.goods_cart.current_promotions[i].dis_pro_money =($rootScope.goods_cart.info.total_money - $rootScope.goods_cart.info.total_money * (0.1) * parseFloat(n.rebate)).toFixed(2);
                                    break;
							    case 10://无门槛促销
                                    var promoney = no_door_pro_logic(n);
									discount_money = discount_money+promoney;
                            
                            }
                            
                            //促发促销
                            if(discount_money >0){
                                $.each($rootScope.goods_cart.list, function (k, v) {
                                    $rootScope.goods_cart.list[k].goods_status = 1;
                                });
                            }
                            var dis_coupon_money = 0;
                            var temp_dis_money = 0;
                            temp_dis_money = dis_coupon_money = get_money_coupon_bind_promotion(n.promotion_rule_id,n.can_used_num,total_money,discount_money);
                            dis_coupon_money = dis_coupon_money - discount_money;
                            $rootScope.goods_cart.current_promotions[i].favorable_money = temp_dis_money;
                            $rootScope.goods_cart.current_promotions[i].isUse = true;
                            $rootScope.goods_cart.current_promotions[i].dis_coupon_money = dis_coupon_money;
                            discount_money = temp_dis_money; 
                        }
                    });
                    
                     $.each($rootScope.goods_cart.current_promotions, function (i, n) {
                        if (!Promotion.check_current_prom(n.promotion_rule_id, $rootScope.goods_cart.available_promotions)) {
                            if(n.promotion_type == 0 || n.promotion_type == 2 || n.promotion_type == 4 || n.promotion_type == 7 || n.promotion_type == 10){
                                clear_cart_goods_promotion_id(i);
                                delete $rootScope.goods_cart.current_promotions[i];
                                change_coupon_pro_flag(i,0);
                            }
                            
                           
                            
                        }
                     });
                    return discount_money;
                };
                //绑定促销的优惠券优化金额
                var get_money_coupon_bind_promotion = function(promotionid,num,total_money,discount_money){
                    
                    var n = $rootScope.goods_cart.couponData[promotionid];
                    if(n == undefined){
                        return discount_money;
                    }
                    
                    //折扣券  做完(优惠券不可叠加)
                    if (n.coupon.type == 1) {
                       
                        discount_money = discount_money + total_money - (total_money * parseFloat(n.coupon.rebate));
                        
                    }
                    //随机金额券
                    if (n.coupon.type == 3 || n.coupon.type == 0) {
                        
                        discount_money = discount_money + parseFloat(n.detail.money*num);
                       
                    }
                    return discount_money;
                };

                //添加优惠虚拟商品
                var add_coupon_goods = function(discount_money){
                    $rootScope.goods_cart.couponGood.price = parseFloat(0-discount_money).toFixed(2)*1;
                }
                //刷新购物车总计
                var refresh_cart_num = function () {
                    var total_num = 0;
                    var total_money = 0;
                    var discount_money = 0;
                    //计算非 赠品 商品金额 包含套组
                    $rootScope.goods_cart.list.forEach(function (o) {
                        if (o.pro_gift == 1) {
                        } else {
                            //购买价是使用原价还是会员价
                            if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                                //如果存在外卡折扣
                                if ($rootScope.zk != '') {
                                    o.BuyPrice = o.SkuPrice * parseFloat($rootScope.zk);
                                } else {
                                    o.BuyPrice = o.SkuPrice;
                                }
                            } else {
                                //如果存在外卡折扣
                                if ($rootScope.zk != '') {
                                    o.BuyPrice = o.SkuVipPrice * parseFloat($rootScope.zk);
                                } else {
                                    o.BuyPrice = o.SkuVipPrice;
                                }
                            }
                            if (!o.rebate) {
                                if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                                    o.rebate = get_price_rebate(o.BuyPrice, o.SkuPrice);
                                } else {
                                    o.rebate = $rootScope.goods_cart.vip.rebate * get_price_rebate(o.BuyPrice, o.SkuVipPrice);
                                }
                            } else {
                                if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                                    o.rebate = get_price_rebate(o.BuyPrice, o.SkuPrice);
                                } else {
                                    o.rebate = $rootScope.goods_cart.vip.rebate * get_price_rebate(o.BuyPrice, o.SkuVipPrice);
                                }
                                //折扣改变
                            }
                            o.BuyPrice = o.BuyPrice * o.rebate*1;
                            o.money = o.BuyPrice * o.num*1;//原来没有
                            total_num = total_num * 1 + o.num * 1;
                            total_money = total_money + o.money;
                        }

                    });
                    //存在优惠券
                    //不绑定促销的优惠券
                    if (Object.keys($rootScope.goods_cart.couponData).length > 0) {
                        $.each($rootScope.goods_cart.couponData, function (i, n) {
                            if(n.coupon.promo_id == ''){
                                 //折扣券  做完
                                if (n.coupon.type == 1) {
                                    discount_money = discount_money + total_money - (total_money * parseFloat(n.coupon.rebate));
                                }
                                //随机金额券
                                if (n.coupon.type == 3 || n.coupon.type == 0) {
                                    discount_money = discount_money + parseFloat(n.detail.money);
                                }
                            }
                           
                        });
                    }
                    var info = {
                        'total_money':total_money,
                        'total_num':total_num
                    };
                    $rootScope.goods_cart.info.discount_money = 0;
                    $rootScope.goods_cart.info.total_num = info.total_num;
                    $rootScope.goods_cart.info.total_money = info.total_money;
                    $rootScope.goods_cart.info.need_money = $rootScope.goods_cart.info.total_money - $rootScope.goods_cart.info.discount_money;
                    $rootScope.goods_cart.info.need_money = $rootScope.goods_cart.info.need_money > 0 ? $rootScope.goods_cart.info.need_money : 0;
                    //计算 赠品 及 套组 商品金额
                    info = refresh_group_promo_goods(info);
                    //计算商品金额信息 及 小票单金额信息
                    $rootScope.goods_cart.info.total_num = info.total_num;
                    $rootScope.goods_cart.info.total_money = info.total_money;
                    $rootScope.goods_cart.info.need_money = $rootScope.goods_cart.info.total_money - $rootScope.goods_cart.info.discount_money;
                    $rootScope.goods_cart.info.need_money = $rootScope.goods_cart.info.need_money > 0 ? $rootScope.goods_cart.info.need_money : 0;

                    var deferred = $q.defer();
                    return Promotion.get_available_promotion().then(function (success) {
                        //计算 响应促销优惠金额
                        var pro_money = get_promotion_discount_money(total_money);
                        discount_money += (pro_money >= 0)?pro_money:0;
                        //discount_money 订单小票 总优惠金额
                        //根据优惠信息计算小票单支付金额
						$rootScope.goods_cart.info.discount_money = discount_money + $rootScope.goods_cart.info.cut_money;
						$rootScope.goods_cart.info.need_money = $rootScope.goods_cart.info.total_money - $rootScope.goods_cart.info.discount_money;
						$rootScope.goods_cart.info.need_money = $rootScope.goods_cart.info.need_money > 0 ? $rootScope.goods_cart.info.need_money : 0;
						set_cart_goods_promotion_id();
						$rootScope.goods_cart.info.discount_money = $rootScope.goods_cart.info.need_money > 0 ?$rootScope.goods_cart.info.discount_money: $rootScope.goods_cart.info.total_money;
						//添加优惠虚拟商品
                        add_coupon_goods($rootScope.goods_cart.info.discount_money);
                        //合并不是促销的商品
                        merge_goods_carts_no_pro();
                        deferred.resolve(1);
                        return deferred.promise;
                    });


                };
                //设置关联促销
                var set_related_promotion = function (rule_id) {
                    for (var k = 0; k < $rootScope.goods_cart.list.length; k++) {
                        $rootScope.goods_cart.list[k].related_promotionid = rule_id;
                    }
                };
                //使用优惠券标志
                var use_flag_promotion = function(promotionid,goods_status){
                    if($rootScope.goods_cart.couponData[promotionid] == undefined){
                        return;
                    }
                    var n ={};
                    for(var i = 0; i<$rootScope.goods_cart.couponData[promotionid].coupon.coupon_code.length;i++ ){
                        n = $rootScope.goods_cart.couponData[promotionid].coupon.coupon_code[i];
                        if(!n.is_use){
                            $rootScope.goods_cart.couponData[promotionid].coupon.coupon_code[i].is_use = true;
                            $rootScope.goods_cart.couponData[promotionid].coupon.coupon_code[i].goods_status = goods_status;
                            break;
                        }
                    }
                    
                };
                

                //添加商品促销
                var change_promotion_goods = function (current_pro,last_current_pro) {
                    var is_pro = false; //是否促发促销
                    var n = {};
                    $.each(current_pro, function (i, detail) {
                        if (Promotion.check_current_prom(detail.promotion_rule_id, last_current_pro)) {
                            n = $rootScope.goods_cart.current_promotions[detail.promotion_rule_id];
							var can_used_num = 1;
                            switch (parseInt(n.promotion_type)) {
								
                                case 1://满额赠件 
								case 8:
								case 9:
                                case 3://满件赠件 
                                    //TODO 购物车中添加物品
                                    if(n.used_num == 0){
                                        //for(var i = 0; i < can_used_num; i++){
                                            add_gift_to_cartlist(n.gift_list, n.promotion_rule_id, n.promotion_type, n.goods_status);
                                        //}
                                    }

                                    // else{
                                    //     if(can_used_num < n.used_num){
                                    //         var del_num = n.used_num - n.can_used_num;
                                    //         //删除赠品
                                    //         for(var i = 0; i < del_num ; i++){
                                    //             del_promotionGift(n.gift_list);
                                    //         }
                                    //     }else if(can_used_num > n.used_num){
                                    //         var add_num = can_used_num - n.used_num;
                                    //         for(var i = 0; i < n.add_num; i++){
                                    //             add_gift_to_cartlist(n.gift_list, n.promotion_rule_id, n.promotion_type, n.goods_status);
                                    //         }
                                    //     }
                                    // }
                                    if(can_used_num != n.used_num){
                                        is_pro = true;
                                        $.each($rootScope.goods_cart.list, function (k, v) {
                                           
                                            $rootScope.goods_cart.list[k].goods_status = n.goods_status;
                                        });
                                    }
                                    $rootScope.goods_cart.current_promotions[n.promotion_rule_id].used_num = can_used_num;
                                    change_coupon_pro_flag(n.promotion_rule_id,can_used_num);
                                    
                                    break;
                                case 5://套组
                                    if(n.used_num == 0){
                                        for(var i = 0; i < n.can_used_num; i++){
                                            add_gift_to_cartlist(n.group_goods, n.promotion_rule_id, n.promotion_type, n.goods_status);
                                        }
                                    }else{
                                        if(n.can_used_num > n.used_num){
                                            var add_num = n.can_used_num - n.used_num;
                                            for(var i = 0; i < n.add_num; i++){
                                                add_gift_to_cartlist(n.group_goods, n.promotion_rule_id, n.promotion_type, n.goods_status);
                                            }
                                            
                                        }
                                    }
                                    if(n.can_used_num != n.used_num){ //TODO 只有大于情况
                                        //使用优惠券标志
                                        use_flag_promotion(n.promotion_rule_id,n.goods_status);
                                    } 
                                    $rootScope.goods_cart.current_promotions[n.promotion_rule_id].used_num = n.can_used_num;
                                    is_pro = true;
                                    
                                   // }
                                    break;
                                case 6:
                                    //积分
                                    break;
                            }
							
                            
                            //叠加促销
                            $rootScope.goods_cart.current_promotions[n.promotion_rule_id].isUse = true;
                            set_cart_goods_promotion_id();
							
                            
                        } else {
                            
                            //处理促销物品
                            var goods_list = [];
                            goods_list = goods_list.concat($rootScope.goods_cart.list);
                            var v = {};
                            var j = 0;
                            var is_del = false;
                            for (j = 0; j < goods_list.length; j++) {
                                v = goods_list[j]; //promotionid != undefined && (v.promotionid == detail.promotion_rule_id
                                if (v.promotionid == detail.promotion_rule_id ||(v.whole_pro == detail.record_code || v.bind_pro == detail.record_code)) {
                                    if (parseInt(detail.promotion_type) == 1 || parseInt(detail.promotion_type) == 3 || parseInt(detail.promotion_type) == 5 || parseInt(detail.promotion_type) == 9 || parseInt(detail.promotion_type) == 8) {
                                        for (var k = 0; k < $rootScope.goods_cart.list.length; k++) {
                                            if ($rootScope.goods_cart.list[k].SkuCode == v.SkuCode) {
                                                $rootScope.goods_cart.list.splice(k, 1);
                                                is_del = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            if (is_del) {
                                if ($rootScope.goods_cart.current_promotions[detail.promotion_rule_id] != undefined) {
                                    clear_cart_goods_promotion_id(detail.promotion_rule_id);
                                    $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].isUse = false;
                                    $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].favorable_money = 0;
                                    $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].dis_coupon_money = 0; 
                                    $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].dis_pro_money = 0; 
                                    delete $rootScope.goods_cart.current_promotions[detail.promotion_rule_id];
                                    
                                }
                                refresh_cart_num();
                            }
                        }

                    });
                    if (is_pro) {
                        $.each($rootScope.goods_cart.list, function (k, v) {
                            $rootScope.goods_cart.list[k].is_promotion = 1;
                        });
                    }
                };

                //获取最终当前使用的促销信息
                var get_last_current_promotions = function () {
                    //最终当前使用的促销
                    var last_current_pros = {};
                    var ablepro_arr = Object.keys($rootScope.goods_cart.available_promotions);
                    var ablepro_len = ablepro_arr.length;
                    var ablpro = {};
                    var curpro_arr = Object.keys($rootScope.goods_cart.current_promotions);
                    var curpro_len = curpro_arr.length;
                    var curpro = {};
                    for(var able = 0;able<ablepro_len;able++){
                        ablpro = $rootScope.goods_cart.available_promotions[ablepro_arr[able]];
                        for(var cur = 0; cur<curpro_len;cur++){
                            curpro = $rootScope.goods_cart.current_promotions[curpro_arr[cur]];
                            if(ablpro.promotion_rule_id == curpro.promotion_rule_id || ablpro.promotion_type == 5){
                                if(!last_current_pros[curpro.promotion_rule_id]){
                                    last_current_pros[curpro.promotion_rule_id] = curpro;
                                }
                            }
                        }
                    }
                    return last_current_pros;
                };


                //刷新购物车关联促销
                var refresh_cart_to_promotion = function () {
                    if ($rootScope.goods_cart.list.length == 0) {
                        return;
                    }
                    if (Object.keys($rootScope.goods_cart.available_promotions).length <= 0 && Object.keys($rootScope.goods_cart.current_promotions).length <= 0) {
                        return;
                    }
                    //最终当前使用的促销
                    var last_current_pros = {};
                    last_current_pros = get_last_current_promotions();
                    //检查当前可以促销
                    change_promotion_goods($rootScope.goods_cart.current_promotions, last_current_pros);
                };
                //判断是否合并
                var check_goods_merge = function (m, temp_goods) {
                    if((temp_goods.bind_pro || m.bind_pro || temp_goods.goods_status > 0 || m.goods_status >0) && (!m.pro_gift&&!temp_goods.pro_gift)){
                        return false;
                    }else if((temp_goods.whole_pro || m.whole_pro || temp_goods.goods_status>0 || m.goods_status>0) && (!m.pro_gift&&!temp_goods.pro_gift)){
                        return false;
                    }else if ( temp_goods.SkuCode == m.SkuCode && ((temp_goods.rebate == m.rebate) || (temp_goods.SkuPrice == m.SkuPrice)) && (temp_goods.goods_status == m.goods_status)) {
                        return true;
                     }
                    return false;
                };
                //合并不是促销的商品
                var merge_goods_carts_no_pro = function () {
                    if ($rootScope.goods_cart.list.length <= 0) { //两个以上的商品需要合并
                        return;
                    }
                    var merge_goods_list = [];
                    var final_goods_list = [];
                    var temp_goods;
                    // merge_goods_list = $rootScope.goods_cart.pro_list.concat();  //浅拷贝，对象里面的对象没有复制
                    merge_goods_list = angular.copy($rootScope.goods_cart.list);
                    if (merge_goods_list.length > 0) {
                        temp_goods = JSON.parse(JSON.stringify(merge_goods_list[0]));
                    }
                    var index = 0;
                    $.each(merge_goods_list, function (j, m) {
                        if (j != 0) {
                            //拆分过的商品
                            if (check_goods_merge(m, temp_goods)) {
                                final_goods_list[index].money = final_goods_list[index].money * 1 + m.money * 1;
                                final_goods_list[index].num = final_goods_list[index].num * 1 + m.num * 1;
                            } else {   //没有拆分的商品
                                final_goods_list.push(m); //插入未拆分的商品
                                index++;
                                temp_goods = m;
                            }

                        } else {
                            final_goods_list.push(temp_goods);
                        }

                    });
                    final_goods_list.forEach(function (e) {
                        e.BuyPrice = e.money / e.num;
                        e.rebate = isNaN(e.BuyPrice / e.SkuPrice) ? 1 : e.BuyPrice / e.SkuPrice;
                    });
                    //baison_app.api.alert({msg:final_goods_list});
                    if (final_goods_list.length > 0) {
                        $rootScope.goods_cart.list = angular.copy(final_goods_list);
                    }
                };



                //刷新购物成
                var refresh_cart = function () {
                    
                    //购物车数量刷新
                    refresh_cart_num();
                    //促销管理逻辑
                    refresh_cart_to_promotion();

                };
                var refresh_cart_change = function () {
                    refresh_cart_to_promotion();
                    // Promotion.get_available_promotion().then(function (success) {
                    //     refresh_cart_to_promotion();
                    // });
                };
                //同享促销是否可以使用
			    var is_share_apply_promotion = function(detail){
					var is_apply = false;
					var cur_pro_keys = Object.keys($rootScope.goods_cart.current_promotions);
					if(detail.is_share == 0){ //独享
						if(cur_pro_keys.length > 0){
							return false;
						}
					}
					var n = {};
					var relation = {};
					for(var i = 0; i < cur_pro_keys.length; i++){
						n = $rootScope.goods_cart.current_promotions[cur_pro_keys[i]];
						if(n.isUse){
						    is_apply = false;
						   if(n.is_share == 0){ //独享
							   is_apply = false;
							   break
						   }
						   if(n.is_share == 1){ //同享
							   if(n.relation){
								   for(var j = 0; j<n.relation.length;j++){
									   relation = n.relation[j];
									   if((relation.promo_code_rela == detail.record_code || relation.promo_code == detail.record_code)
                                            &&detail.options[0].vip_price <= $rootScope.goods_cart.info.need_money){
										   is_apply = true;
										   break;
									   }
								   }
							   }else{
								   is_apply = false;
							   }
							   if(!is_apply){
							       break;
                               }
						   }
						}
					}
					if(cur_pro_keys.length <= 0){
						is_apply = true;
					}
					return is_apply;
				}
				
				
                //是否可以应用该促销
                var is_check_apply_promotion = function(detail){
					//满件赠->满件减->满额减->满额赠  优先规则 优先计算
                    // 所有促销类型
                    // 无门槛 10，
                    // 套组   5，
                    // 满件赠件（每满）8，// 满件赠件 3，
                    // 满件减钱 2，
                    // 满额减钱 0，// 满额减（每满）7，
                    // 满额赠件（每满）9,// 满额赠件 1，
                    // 满额打折 4，
                    // 促销优先级顺序

                    var pro_sx = [10,8,3,2,7,0,9,1]; //促销优先级顺序列表
                    var tj_sx = [{
                        'index':3,  //同级索引
                        'type':4    //同级类型
                    }];
					var proindex = pro_sx.indexOf(detail.promotion_type);
					var lowindex = -1;
					var tjindex = -1;
					if(proindex != -1){
					    //获取对应的低级促销信息
                        $.each($rootScope.goods_cart.current_promotions, function (i, n) {
                            if(n.isUse){
                                lowindex = -1;
                                //低优先级促销查询
                                for(var i = proindex ;i < pro_sx.length;i++){
                                    if(pro_sx[i] == n.promotion_type){
                                        lowindex = i;
                                        break;
                                    }
                                }
                                //同级促销查询处理   同级促销可以同时使用  限促销优先级
                                for(var j = 0;j<tj_sx.length;j++){
                                    if(tj_sx[j].type == n.promotion_type){
                                        tjindex = tj_sx[j].index;
                                        break;
                                    }
                                }
                                if(proindex == tjindex){
                                    lowindex = -1;
                                }
                                if(lowindex != -1){
                                    del_current_promotion(n);
                                }
                            }

                        });
                    }
                    /*
					var lowindex = -1;
					if(highindex != -1){
						$.each($rootScope.goods_cart.current_promotions, function (i, n) {
							if(n.isUse){
							   lowindex = low_pro.indexOf(n.promotion_type);
							   if(lowindex != -1){
								   del_current_promotion(n);
							   }
							}
							
						});
					}*/
                };
                //设置相应的促销信息
                var set_goods_cart_promotion = function(detail){
                    var index = 0;
                    $rootScope.goods_cart.list.forEach(function(o){
                        index = detail.goods_list.indexOf(o.SkuCode);
                        if(index != -1){
                            o.promotionid = detail.promotion_rule_id;
                        }else if(detail.is_goods == 0){
                            o.promotionid = detail.promotion_rule_id;
                        }
                    });
                    
                };
                
                //添加应用促销
                var add_current_promotion = function (detail) {

                    var _exists = false;
                    ////选择促销内已有独享的，不能重复选择独享
                    if ($rootScope.goods_cart.share_promotion_id != 0 && $rootScope.goods_cart.share_promotion_id != detail.promotion_rule_id) {
                        if (detail.is_share == 0) {
                            _exists = true;
                        }
                    }
                    //不存在
                    if (!_exists) {

                        if (detail.is_coupon == 1 && $rootScope.goods_cart.couponData[detail.promotion_rule_id] == undefined) {
                            baison_app.api.toast({msg: $rootScope.language.TIP_GOODS_COUPON});
                            del_current_promotion(detail);
                            $rootScope.goods_cart.giftnum = 0;
                            $rootScope.goods_cart.giftednum = 0;
                            return;
                        }
                        
                        $rootScope.goods_cart.current_promotions[detail.promotion_rule_id] = detail;
                        $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].isUse = true;
                        $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].favorable_money = 0;
                        $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].dis_coupon_money = 0; 
                        $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].dis_pro_money = 0; 

                        if (detail.is_share == 0) {
                            $rootScope.goods_cart.share_promotion_id = detail.promotion_rule_id;
                        }
                        $rootScope.goods_cart.current_promotions[detail.promotion_rule_id].used_num = 0;

                        //设置相应的促销信息
                        set_goods_cart_promotion(detail);

                        //刷新购物车
                        refresh_cart();
                    }

                };
                //删除应用促销
                var del_current_promotion = function (detail) {
                    var _exists = false;
                    $.each($rootScope.goods_cart.current_promotions, function (i, n) {
                        if (detail['promotion_rule_id'] == n['promotion_rule_id']) {
                            _exists = true;
                        }
                    });
                    if (_exists) {
                        var promotype = detail.promotion_rule_id.toString()+detail.promotion_type;
                        del_pro_gift(promotype);
                        deal_promotionData(detail.promotion_rule_id);
                        clear_cart_goods_promotion_id(detail.promotion_rule_id);
                        delete $rootScope.goods_cart.current_promotions[detail.promotion_rule_id];
                        delete $rootScope.goods_cart.select_promotions[detail.promotion_rule_id];
                        if (detail.is_share == 1) {
                            $rootScope.goods_cart.share_promotion_id = 0;
                        }
                        $.each($rootScope.goods_cart.available_promotions, function (i, n) {

                            if (detail['promotion_rule_id'] == n['promotion_rule_id']) {
                                $rootScope.goods_cart.available_promotions[i].selected = false;
                            }
                        });
                        //刷新购物车
                        refresh_cart();
                    }

                };
                //添加促销(宫格选择促销)
                var add_select_promotion = function (detail) {

                    var _exists = false;
                    $.each($rootScope.goods_cart.select_promotions, function (i, n) {

                        if (detail['promotion_rule_id'] == n['promotion_rule_id']) {
                            _exists = true;
                        }
                    });

                    //不存在
                    if (!_exists) {
                        $rootScope.goods_cart.select_promotions.push(detail);
                    }
                    //baison_app.api.alert({msg:$rootScope.goods_cart.select_promotions,title:'selectpromtions'});
                    add_current_promotion(detail);
                };
                //
                var check_coupon = function(couponcodes,coupon_code){
                    for(var i = 0; i < couponcodes.length; i++){
                        if(couponcodes[i].code == coupon_code){
                            baison_app.api.toast({msg:'已使用'});
                            return 0;
                        }
                    }
                    return 1;
                };
                //jinhua.gu
                //向优惠券数组添加优惠券信息 //, availCoupon, _promotion
                var add_to_couponData = function (coupon, detail) {
                    var coupon_code = detail.coupon_code;
                    coupon.num = 1;
                    coupon.coupon_code =[];
                    coupon.coupon_code.push({'code':coupon_code,'is_use':false});
                    //不绑定促销的优惠券
                    if (coupon.promo_id == '') {
                        $rootScope.goods_cart.couponData[coupon.coupon_id] = {
                            'coupon': coupon,
                            'detail': detail,
                            
                        };
                    } else {
                        if($rootScope.goods_cart.couponData[coupon.promo_id] != undefined && check_coupon($rootScope.goods_cart.couponData[coupon.promo_id].coupon.coupon_code,coupon_code)){
                           $rootScope.goods_cart.couponData[coupon.promo_id].coupon.num +=1;
                           $rootScope.goods_cart.couponData[coupon.promo_id].coupon.coupon_code.push({'code':coupon_code,'is_use':false});
                        }else{
                            
                            $rootScope.goods_cart.couponData[coupon.promo_id] = {
                                'coupon': coupon,
                                'detail': detail,
                               
                            };
                        }
                    }
                    //刷新购物车
                    refresh_cart();
					//
					var coupon_pro = false;
					$.each($rootScope.goods_cart.available_promotions, function (i, n) {
						if(n.promotion_rule_id == coupon.promo_id){
							coupon_pro = true;
						}
					});
					if(!coupon_pro){
						 baison_app.api.toast({msg:'当前商品与优惠券不匹配'});
					}
                   
                };
                //删除促销的优惠赠品
                var del_promotionGift = function(gift_list){
                    for(var i = 0; i < gift_list.length; i++){
                        v = gift_list[i];
                        for (var k = 0; k < $rootScope.goods_cart.list.length; k++) {
                            if ($rootScope.goods_cart.list[k].SkuCode == v.sku) {
                                $rootScope.goods_cart.list.splice(k, 1);
                            }
                        }
                    }
                    
                    
                };

                // 清除对应促销赠品信息
                var clear_pro_gift_goods = function(promotionid){
                    $rootScope.goods_cart.list.forEach(function(o){
                        if(o.promotionid == promotionid){
                            o.promotionid = '';
                        }
                    });
                };

            //删除 促销赠品
            var del_pro_gift = function (promotype) {
                var goods_list = [];
                goods_list = angular.copy($rootScope.goods_cart.list);
                var v = {};
                for (var j = 0; j < goods_list.length; j++) {
                    v = goods_list[j];
                    if (v.promotype == promotype) {
                        for (var k = 0; k < $rootScope.goods_cart.list.length; k++) {
                            if ($rootScope.goods_cart.list[k].SkuCode == v.SkuCode) {
                                $rootScope.goods_cart.list.splice(k, 1);
                                break;
                            }
                        }
                    }

                }
            }
            //删除促销套组商品
                var del_group_goods = function(goods_status){
                    var goods_list = [];
                    goods_list = goods_list.concat($rootScope.goods_cart.list);
                    var v = {};
                    var j = 0;
                    var promotionid = 0;
                    for (j = 0; j < goods_list.length; j++) {
                        v = goods_list[j]; 
                        promotionid = v.promotionid;
                        if (v.goods_status== goods_status) {
                             if($rootScope.goods_cart.current_promotions[promotionid] != undefined){
                                delete $rootScope.goods_cart.current_promotions[promotionid];
                                //$rootScope.goods_cart.available_promotions[promotionid].selected = false;
                            }                           
                            for (var k = 0; k < $rootScope.goods_cart.list.length; k++) {
                                if ($rootScope.goods_cart.list[k].SkuCode == v.SkuCode && $rootScope.goods_cart.list[k].goods_status == v.goods_status) {
                                    $rootScope.goods_cart.list.splice(k, 1);
                                    break;
                                }
                            }
                        }
                        
                    }
                    if($rootScope.goods_cart.list.length <= 0){
                        $.each($rootScope.goods_cart.current_promotions,function(pid,n){
                            delete $rootScope.goods_cart.current_promotions[pid];
                            //$rootScope.goods_cart.available_promotions[pid].selected = false;
                        });   
                    }
                };
                //删除优惠券数组中的一个优惠券
                var delete_from_couponData = function (i, pid) {
                    //不绑定促销的优惠券
                    if (pid == '') {
                        delete $rootScope.goods_cart.couponData[i];
                    } else {
                        if($rootScope.goods_cart.couponData[pid].coupon.num > 1){
                            $rootScope.goods_cart.couponData[pid].coupon.num -=1; 
                            if($rootScope.goods_cart.couponData[pid].coupon.coupon_code[0].goods_status != undefined){
                                goods_status =   $rootScope.goods_cart.couponData[pid].coupon.coupon_code[0].goods_status; 
                                del_group_goods(goods_status);
                                 
                            }
                            
                            $rootScope.goods_cart.couponData[pid].coupon.coupon_code.splice(0,1);
                            
                        }else{
                            delete $rootScope.goods_cart.couponData[pid];
                            //取消独享设定
                            if ($rootScope.goods_cart.share_promotion_id != 0) {
                                if ($rootScope.goods_cart.current_promotions[pid] && $rootScope.goods_cart.current_promotions[pid].is_share == 1) {
                                    $rootScope.goods_cart.share_promotion_id = 0;
                                }
                            }
                            
                        }
                        del_group_goods(1);  
                        
                        
                    }
                    if($rootScope.goods_cart.list.length <= 0){
                        $rootScope.goods_cart.couponData = {};
                    }else{
                        //刷新购物车
                        refresh_cart();
                    }
                    

                };
                //处理促销商品
                var deal_promotionData = function(promotionid){
                    
                    //优惠券不绑定促销
                    if($rootScope.goods_cart.couponData[promotionid] == undefined){
                       
                        return;
                    }
                    
                    //优惠券绑定促销 
                    //单张优惠券
                    if($rootScope.goods_cart.couponData[promotionid].coupon.coupon_code.length == 1){
                        //取消独享设定
                        if ($rootScope.goods_cart.share_promotion_id != 0) {
                            if ($rootScope.goods_cart.current_promotions[promotionid] && $rootScope.goods_cart.current_promotions[promotionid].is_share == 1) {
                                $rootScope.goods_cart.share_promotion_id = 0;
                            }
                        }
                        
                        delete $rootScope.goods_cart.couponData[promotionid];
                        
                        
                    }else{ //多张优惠券
                        $rootScope.goods_cart.couponData[promotionid].coupon.num -=1; 
                        
                        $rootScope.goods_cart.couponData[promotionid].coupon.coupon_code.splice(0,1);
                        
                        
                    }
                };
                //购物车里是否优惠券处理
                var deal_goods_cart_couponData = function(){
                    if($rootScope.goods_cart.list.length == 0){
                        $rootScope.goods_cart.couponData = {};
                    }
                };
                //向购物车删除一个商品
                var delete_from_cart = function (i) {
                    var promotionid = $rootScope.goods_cart.list[i].promotionid;
                    var pro_gift = $rootScope.goods_cart.list[i].pro_gift;
                    var goods_status = $rootScope.goods_cart.list[i].goods_status;
                    var whole_pro = $rootScope.goods_cart.list[i].whole_pro;
                    var bind_pro = $rootScope.goods_cart.list[i].bind_pro;
                    
                    if(promotionid != undefined && promotionid != '' || whole_pro || bind_pro ){
                        goods_status = $rootScope.goods_cart.list[i].goods_status;
                        del_group_goods(goods_status); 
                        deal_promotionData(promotionid);
                    }else{
                        $rootScope.goods_cart.list.splice(i, 1);
                    }
                    //购物车内商品数量变动，取消抹零
                    $rootScope.goods_cart.info.cut_money = 0;
                    if($rootScope.goods_cart.list.length <= 0){
                        var vipinfo =angular.copy($rootScope.goods_cart.vip);
                        init(); 
                        $rootScope.goods_cart.vip = vipinfo;
                    }else{
                        refresh_cart();
                    }
                    
                };



                //清空整个购物车
                var clear_cart = function () {
                    init();
                   
                    //归零
                    $rootScope.zk = '';
                    $rootScope.yxdjsy = '';
                    
                };
                //设置当前购物车中的VIP信息
                var set_current_vip = function (vip) {
                    if (vip.vip_code != '') {
						if(!$rootScope.goods_cart){
							init();
						}
                        $rootScope.goods_cart.vip = vip;

                        var nowTime = new Date();
                        var nowMonth = timeStamp2String(nowTime, 'date');
                        //生日格式为1999-09-09  或者   09-09   用slice取倒数第5和4位为月份
                        if (vip.birthday && vip.birthday.slice(-5) == nowMonth.slice(-5)) {
                            $rootScope.goods_cart.birthday = 1;
                        } else {
                            $rootScope.goods_cart.birthday = 0;
                        }
                        if ($rootScope.goods_cart.vip.customer_integral == 0) {
                            $rootScope.goods_cart.vip.customer_integral = vip.vip_integral;
                        } else {
                            $rootScope.goods_cart.vip.vip_integral = $rootScope.goods_cart.vip.customer_integral;
                        }
                        refresh_cart();
                    }
                };

                //支付部分 ====================================================
                //向当前购物车添加一种支付方式 支付代码/金额或抵扣金额/支付备注信息
                var add_check = function (code, name, pay_money, final_money, coupon_code, remark,fund_bill_list) {
                    //add by liuwei 积分添加虚拟商品 20180115
                    if( code == '004' ){
                        $rootScope.goods_cart.couponGood.price = $rootScope.goods_cart.couponGood.price-final_money*1;
                    }
                    $rootScope.goods_cart.checklist.push({
                        code: code,
                        name: name,
                        pay_money: code == '003'?0:pay_money,
                        final_money: final_money,
                        coupon_code: coupon_code,
                        remark: remark,
                        fund_bill_list:fund_bill_list?fund_bill_list:JSON.stringify([])
                    });
                    refresh_check();
                };
                //从支付列表中清除掉一条支付信息
                var delete_from_check = function (i) {
                    //add by liuwei 积分添加虚拟商品 20180115
                    var data = $rootScope.goods_cart.checklist[i];
                    if( data.code == '004' ){
                        $rootScope.goods_cart.couponGood.price = $rootScope.goods_cart.couponGood.price+data.final_money*1;
                    }
                    $rootScope.goods_cart.checklist.splice(i, 1);
                    refresh_check();
                };
                //清空支付列表
                var clear_check_reset = function () {
                    //add by liuwei 积分添加虚拟商品 20180115
                    $rootScope.goods_cart.checklist.forEach(function (e, index) {
                        if(e.code == '004'){
                            $rootScope.goods_cart.couponGood.price = $rootScope.goods_cart.couponGood.price+e.final_money*1;
                        }
                    });
                    $rootScope.goods_cart.checklist = [];
                    refresh_check();
                };
                //清空支付列表
                var clear_check = function () {
                    $rootScope.goods_cart.checklist = [];
                    refresh_check();
                };
                //查询现金收银为0的索引
                var select_xianjin_zero = function(money){
                    var len = $rootScope.goods_cart.checklist.length;
                    var clist = {};
                    var index = 0;
                    for(var i = 0; i < len; i++){
                        clist = $rootScope.goods_cart.checklist[i];
                        if(clist.code == '001'){ //现金支付
                            if(money > 0){
                                delete_from_check(i);
                            }
                            
                            break;
                        }
                    }
                    if(clist.money && clist.money == 0){
                        return index;
                    }else{
                        return -1;
                    }
                };
                //判断传入的支付列表与已经使用的支付方式是否有重复，用于冲突检测
                //冲突返回true 没有冲突为false
                var has_check = function (code_list) {
                    var checked = [];
                    $rootScope.goods_cart.checklist.forEach(function (e) {
                        checked.push(e.code);
                    });
                    var used = false;
                    code_list.forEach(function (e) {
                        if (-1 != checked.indexOf(e)) {
                            used = true;
                        }
                    });
                    return used;
                };
                //判断整单是否已经支付完毕
                var is_pay_over = function () {
                    refresh_check();
                    return $rootScope.goods_cart.info.daifu_money <= 0;
                };
                //刷新已支付的信息
                var refresh_check = function () {
                    $rootScope.goods_cart.info.pay_money = 0.00;
                    $rootScope.goods_cart.info.final_money = 0.00;
                    $rootScope.goods_cart.checklist.forEach(function (e) {
                        $rootScope.goods_cart.info.pay_money += e.pay_money*1;
                        $rootScope.goods_cart.info.final_money += e.final_money*1;
                    });

                    $rootScope.goods_cart.info.daifu_money = $rootScope.goods_cart.info.need_money - $rootScope.goods_cart.info.final_money;
                    $rootScope.goods_cart.info.charge_money = $rootScope.goods_cart.info.pay_money - $rootScope.goods_cart.info.need_money;
                    $rootScope.goods_cart.info.charge_money = ($rootScope.goods_cart.info.charge_money > 0) ? $rootScope.goods_cart.info.charge_money : 0;
                };
                //抹零
                var cut_money = function () {
                    var configData = $api.getStorage('configData');
                    if (configData.moling == 0) {
                        baison_app.api.alert({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_GOODS_CUTMONEY});
                        return;
                    } else {
                        //抹零处理函数
                        var molingOperation = function (value, rule) {
                            switch (rule) {
                                case "moling_rule_sw": //舍位 上取整
                                    value = Math.floor(value);
                                    break;
                                case "moling_rule_jw": //进位 下取整
                                    value = Math.ceil(value);
                                    break;
                                case "moling_rule_sswr": //四舍五入
                                default:
                                    value = Math.round(value);
                                    break;
                            }

                            return value;
                        };



                        var _g_money = 0;
                        var _cut_money = 0;
                        if (configData.molingtype == 0) {
                            //抹到元
                            _g_money = molingOperation($rootScope.goods_cart.info.need_money, configData.molingRule);
                            //_g_money = Math.floor($rootScope.goods_cart.info.need_money / 10) * 10;
                        } else if (configData.molingtype == 1) {
                            //抹到角
                            _g_money = molingOperation($rootScope.goods_cart.info.need_money * 10, configData.molingRule) / 10;
                            //_g_money = Math.floor($rootScope.goods_cart.info.need_money);
                        }
                        _cut_money = $rootScope.goods_cart.info.need_money - _g_money;

                        $rootScope.goods_cart.info.need_money = _g_money;

                        $rootScope.goods_cart.info.cut_money = $rootScope.goods_cart.info.cut_money + _cut_money;
                        refresh_cart();
                    }
                };
                //清空抹零
                var cancel_cut_money = function () {

                    $rootScope.goods_cart.info.cut_money = 0;
                    refresh_cart();

                };

                
                //通过sku获取所有套餐明晰(过期促销去除)
                var get_promotion_rule_group_detail = function (sku) {
                    var deferred = $q.defer();
                    var promise = deferred.promise;
                    var _time = timeStamp2String(0, 'datetime');
                    var _shop_code = $rootScope.current_shop.ShopCode;
                    var _sql_shop = 'select * from PosPromotionRuleGroupDetail as detail where sku = "' + sku
                        + '" and detail.promotion_rule_id in ( select promotion_rule_id from PosPromotionRule as rule'
                        + ' inner join PosPromotionRuleShop as shop on shop.pid = rule.promotion_rule_id '
                        +' where  shop.shop_code="' + _shop_code + '"'+' and begin_time <= "' + _time + '" and end_time >= "' + _time + '" and is_stop = 0 )';

                    var _sql_no_shop = 'select * from PosPromotionRuleGroupDetail as detail where sku = "' + sku
                        + '" and detail.promotion_rule_id in ( select promotion_rule_id from PosPromotionRule as rule'
                        +' where rule.is_shop = 0 and begin_time <= "' + _time + '" and end_time >= "' + _time + '" and is_stop = 0 )';
                    return $q.all({
                        'shop':dbSelect('YsPos',_sql_shop),
                        'noshop':dbSelect('YsPos',_sql_no_shop)
                    });

                   
                };

                //获取明晰 mid
                var get_promotion_rule_group_detail_by_mid = function (mid) {
                    var _sql = 'select (goods_name || "  数量:" || num) as goodsname,* from PosPromotionRuleGroupDetail where promo_group_mid_id="' + mid + '"';
                    return dbSelect('YsPos', _sql);
                };

                //获取明细 group_id
                var get_promotion_rule_groud_detail_by_group_id = function (group_id) {
                    var _sql = 'select * from PosPromotionRuleGroupDetail where promo_group_id="' + group_id + '"';
                    return dbSelect('YsPos', _sql);
                };

                //获取套组
                var get_promotion_rule_group_by_id = function (group_id) {

                    var _sql = 'select * from PosPromotionRuleGroup where promo_group_id="' + group_id + '" limit 1';
                    return dbSelect('YsPos', _sql);
                };

                //获取组别 通过套组id获取下级组
                var get_promotion_rule_group_mid_by_group_id = function (group_id) {
                    var _sql = 'select * from PosPromotionRuleGroupMid where promotion_rule_id="' + group_id + '"';
                    return dbSelect('YsPos', _sql);
                };

                //查找 查找与优惠券中promo_rule_id相关联的促销主表
                var getPromotionRule_by_promo_rule_id = function (id) {
                    var sql = 'select * from PosPromotionRule where promotion_rule_id="' + id + '"';
                    return dbSelect('YsPos', sql);
                };
                //套餐
                var get_sleeve_group_step_1 = function (sku) {

                    sku.is_promotion = 1;
                    $rootScope.goods_cart.promotion_group_list = {};
                    $rootScope.goods_cart.promotion_group_input_sku = {};
                    $rootScope.goods_cart.promotion_group_input_sku.skucode = sku.SkuCode;
                    return get_promotion_rule_group_detail(sku.SkuCode).then(function (ret) {
                        //console.log(ret);
                        var group_detail =[];
                        group_detail = ret.shop.concat(ret.noshop);
                        //console.log(group_detail);
                        var _taozu_list_key = [];//套组不重复id
                        var deferred = {};
                        var promise = {};

                        $rootScope.goods_cart.promotion_group_input_sku.detail = group_detail;
                        $.each(group_detail, function (_group_detail_k, _group_detail_v) {

                            deferred[_group_detail_k] = $q.defer();
                            promise[_group_detail_k] = deferred[_group_detail_k].promise;
                            var _index = $.inArray(_group_detail_v.promo_group_id, _taozu_list_key);

                            if (_index < 0) {
                                _taozu_list_key.push(_group_detail_v.promo_group_id);

                                get_promotion_rule_group_by_id(_group_detail_v.promo_group_id).then(function (group_info) {
                                    $rootScope.goods_cart.promotion_group_list[_group_detail_v.promo_group_id] = group_info[0];
                                    getPromotionRule_by_promo_rule_id(group_info[0].promotion_rule_id).then(function (ret) {
                                        $rootScope.goods_cart.promotion_group_list[_group_detail_v.promo_group_id].is_coupon = ret[0].is_coupon;
                                        deferred[_group_detail_k].resolve('success');
                                    });
                                    //deferred[_group_detail_k].resolve('success');
                                });

                            } else {
                                deferred[_group_detail_k].resolve('error');
                            }
                        });

                        return $q.all(promise);
                    });
                };

                //处理组别数据
                var get_sleeve_group_step_2 = function (group_info) {

                    return get_promotion_rule_group_mid_by_group_id(group_info.promo_group_id).then(function (group_mid_list) {

                        var deferred = {};
                        var promise = {};
                        $.each(group_mid_list, function (_mid_k, _mid_v) {
                            deferred[_mid_k] = $q.defer();
                            promise[_mid_k] = deferred[_mid_k].promise;
                            get_promotion_rule_group_detail_by_mid(_mid_v.promo_group_mid_id).then(function (detail_list) {
                                var mid = _mid_v.promo_group_mid_id;
                                $rootScope.goods_cart.promotion_group_mid_list[mid] = [];
                                deferred[_mid_k].resolve('success');
                                $.each(detail_list, function (_detail_k, _detail_v) {
                                    var detail_id = _detail_v.promo_group_detail_id;
                                    //判断购买商品是否存在该组别    
                                    if (_detail_v.sku == $rootScope.goods_cart.promotion_group_input_sku.skucode) {
                                        //

                                        $rootScope.goods_cart.mid_goods.push({'mid': mid, 'index': _detail_k});
                                    }
                                    $rootScope.goods_cart.promotion_group_mid_list[mid].push(_detail_v);

                                });

                            });

                        });
                        return $q.all(promise);
                    });
                };

                //确认套组
                var apply_group = function (skus) {
                    skus.sel = $rootScope.goods_cart.promotion_group_input_sku.detail[0];
                    var promiseAll = [];
                    $.each(skus, function (i, n) {
                        promiseAll[i] = BaseGoods.get_sku_by_code(n.sku).then(function (data) {

                            if (data.length > 0) {
                                var _sku = data[0];
                                _sku.index = String(new Date().getTime()) + parseInt(Math.random() * 10, 10);
                                _sku.BuyPrice = n.price;
                                _sku.SkuPrice = data[0].SkuPrice;
                                _sku.SkuVipPrice = data[0].SkuVipPrice;
                                _sku.num = n.num;
                                //TODO 用获取的折扣
                                _sku.rebate = 1;
                                //$rootScope.goods_cart.prom_group_goods.push(_sku);
                                //add_gift_to_cart(_sku,5,n.price);
                            }
                        });
                    });


                    return $q.all(promiseAll);
                };

                //初始化空购物车 ========================================
                var init = function () {
					var guidelist = [];
					var is_ready_take=false;
					var today_promotions=[];
					if($rootScope.goods_cart){
						if($rootScope.goods_cart.guidelist){
							guidelist = $rootScope.goods_cart.guidelist;
						}
						if($rootScope.goods_cart.is_ready_take){
							is_ready_take = $rootScope.goods_cart.is_ready_take;
						}
						if($rootScope.goods_cart.today_promotions){
                            $.each($rootScope.goods_cart.today_promotions,function(i,e){
                                e.selected = false;
                            });
							today_promotions = $rootScope.goods_cart.today_promotions;
						}
					}
					
					
					
					
					
					
                    $rootScope.goods_cart = {
                        //是否为退单：0正常，1退单
                        is_return: 0,
                        //单据编号：默认没有，第一次保存时生成
                        record_code: '',
                        //购物车会员信息
                        vip: {
                            vip_code: '',
                            rebate: 1.00
                        },
						//第三方支付状态
						third_settle_status : {},
                        //开始支付中
                        busy:2,
                        //购物车基本信息
                        //应付金额 = 总金额 - 抹零金额 - 优惠金额
                        //实付金额应大于等于应付金额
                        //实付金额 = 实收金额 - 找零金额

                        //举例：---------------------------------------
                        //订单总金额 total_money 1251元
                        //满1000优惠50 优惠金额 discount_money 50元
                        //抹零 cut_money 1元
                        //应付金额 need_money 1200元
                        //顾客积分200抵扣20元  支付列表 004|20|200
                        //此时剩余待支付金额为 1180
                        //实收金额 1200元  pay_money
                        //找零金额 20元 支付列表 001|1180|1200
                        //实付金额 1180元 <---------重要：此为退款时的基础 final_money
                        //此时剩余待支付金额为 0 交易结束

                        info: {
                            total_num: 0.00, //本单总数量

                            total_money: 0.00, //本单总金额  固定死
                            discount_money: 0.00, //优惠金额  固定死
                            cut_money: 0.00, //抹零金额  固定死
                            need_money: 0.00, //应付总金额  固定死

                            daifu_money: 0.00, //剩余待支付金额  变动
                            charge_money: 0.00, //找零金额  变动
                            pay_money: 0.00, //实收总金额 实收的票面金额 包含找零 变动
                            final_money: 0.00 //实付总金额 不包含找零 变动
                        },
                        //赠品数量
                        giftnum:0,
                        //已赠送赠品数量
                        giftednum :0,
						//套组赠品数量
						g_giftnum :0,
						//套组已赠送赠品数量
				        g_giftednum : 0,
                        guidelist:guidelist?guidelist:[],
                        //购物车商品列表
                        list: [],
                        //优惠券信息
                        couponData: {},
                        //优惠券满件送件商品和礼品
                        couponPresentGoodsAndGift: {},
                        select_promotions: [], //促销列表选中的
                        //购物车享受的优惠信息
                        current_promotions: {},
                        //可用的促销方案(包含不生效的)
                        available_promotions:{},
                        today_promotions: today_promotions?today_promotions:{},
                        promotion_goods: [],
                        is_ready_take:is_ready_take?is_ready_take:false,
                        share_promotion_id: 0, //是否存在不同享的促销id,
                        promotion_group_list: {}, //套组
                        promotion_group_mid_list: {}, //组别
                        promotion_group_input_sku: {}, //要买的商品(输入框输入的商品)
                        //组别与物品信息
                        mid_goods: [],
                        //支付列表
                        checklist: [],
                        //收银界面优惠券支付信息列表  （为了为了解决 离线 没有存收银界面优惠券 导致离线小票 没有保存 优惠券结算信息 ）
                        couponlist:[],
                        //虚拟商品
                        couponGood:{
                            'goods_name':'优惠虚拟商品',
                            'goods_code':'TZZK002298',
                            'num':1,
                            'rebate':1,
                            'price':0
                        }
                    };
                    return $rootScope.goods_cart;
                };

                var change_daogou_all = function (daogou_code) {
                    $rootScope.goods_cart.list.forEach(function (e) {
                        e.daogou = daogou_code;
                    });
                };

                //修改商品的规格 
                var change_specifications_in_cart = function(index, newSku)
                {
                    if(index < 0 || index >= $rootScope.goods_cart.list.length)
                    {
                        return;
                    }

                    var oldSku = $rootScope.goods_cart.list[index];

                    //购买价是使用原价还是会员价
                    if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                        newSku.BuyPrice = newSku.SkuPrice;
                    } else {
                        newSku.BuyPrice = newSku.SkuVipPrice;
                    }
                    //购买折扣
                    if (!newSku.rebate) {

                        if ($rootScope.goods_cart.vip.vip_code == '' || typeof $rootScope.goods_cart.vip.vip_code == 'undefined') {
                            newSku.rebate = get_price_rebate(newSku.BuyPrice, newSku.SkuPrice);
                        } else {
                            newSku.rebate = $rootScope.goods_cart.vip.rebate * get_price_rebate(newSku.SkuVipPrice, newSku.SkuPrice);
                        }

                    }
                    //导购字段
                    newSku.daogou = oldSku.daogou;
                    

                    //购买金额
                    newSku.num = oldSku.num;
                    newSku.money = newSku.BuyPrice * newSku.num;
                    newSku.bind_pro = '';
                    newSku.whole_pro = '';

                    $rootScope.goods_cart.list[index] = newSku;
                    //刷新购物车
                    $rootScope.goods_cart.info.cut_money = 0;
                    refresh_cart_num();
                    baison_app.api.toast({msg:$rootScope.language.TIPS_OPTION_SUCCESS});
                }
                return {
                    init: init,
                    cancel_cut_money: cancel_cut_money,
                    add_to_cart: add_to_cart,
                    add_to_cart_batch: add_to_cart_batch,
                    clear_cart: clear_cart,
                    change_daogou_all: change_daogou_all,
                    delete_from_cart: delete_from_cart,
                    set_current_vip: set_current_vip,
                    add_check: add_check,
                    delete_from_check: delete_from_check,
                    clear_check: clear_check,
					//add by liuwei 积分添加虚拟商品 20180115
					clear_check_reset: clear_check_reset,
                    has_check: has_check,
                    refresh_check: refresh_check,
                    is_pay_over: is_pay_over,
                    cut_money: cut_money,
                    refresh_cart_num: refresh_cart_num,
                    refresh_cart: refresh_cart,
                    refresh_cart_change: refresh_cart_change,
                    refresh_group_promo_goods: refresh_group_promo_goods,
                    get_sleeve_group_step_1: get_sleeve_group_step_1,
                    get_sleeve_group_step_2: get_sleeve_group_step_2,
                    add_gift_to_cart: add_gift_to_cart,
                    add_gift_to_cartlist:add_gift_to_cartlist,
                    add_current_promotion: add_current_promotion,
                    del_current_promotion: del_current_promotion,
                    add_select_promotion: add_select_promotion,
                    refresh_cart_to_promotion: refresh_cart_to_promotion,
                    add_to_couponData: add_to_couponData,
                    delete_from_couponData: delete_from_couponData,
                    is_check_apply_promotion:is_check_apply_promotion,
                    change_specifications_in_cart:change_specifications_in_cart,
                    select_xianjin_zero:select_xianjin_zero,
					is_share_apply_promotion:is_share_apply_promotion,
					check_vip_can_use_pro:check_vip_can_use_pro
                };
            }])
        ;
